package com.felix.thread.philosopher;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Chopstick
 *
 * @author xuejinhua
 * @date 2018/10/8 17:28
 */
public class Chopstick {

    private Lock lock;

    private String name;

    public Chopstick(String name) {
        this.lock = new ReentrantLock();
        this.name = name;
    }

    public void pickUp() {
        lock.lock();
        System.out.println(name + ",被阻塞");
    }

    public void putDown() {
        lock.unlock();
        System.out.println("放弃" + name + ",并唤醒所有等待的哲学家");
    }
}
